#include <stdio.h>
#include <stdlib.h>
int root(int n)
{
  int count;
  while (n > 10)
  {
    count = 0;
    while (n)
    {
      count += n % 10;
      n = n / 10;
    }
    n = count;
  }
  return n;
}
int main(int argc, char *argv[])
{
  int n;
  scanf("%d", &n);
  printf("%d", root(n));
  return 0;
}